using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Common.NotifyEvent;

namespace Common
{
	public class QuickExperimentData : NotifyPropertyChanged
	{
		private int _Index = -1;

		private string _QuickExperimentName = string.Empty;

		private string _QuickDefaultPath = string.Empty;

		private ImageSource _ImageSource = new BitmapImage(new Uri("Pack://application:,,,/Images;Component/Other/HomeExperiment.png", UriKind.RelativeOrAbsolute));

		public double Left { get; set; }

		public double Top { get; set; }

		public int Index
		{
			get
			{
				return _Index;
			}
			set
			{
				if (_Index != value)
				{
					_Index = value;
				}
			}
		}

		public bool IsShowInCanvas { get; set; }

		public double CanvasWidth { get; set; }

		public string QuickExperimentName
		{
			get
			{
				return _QuickExperimentName;
			}
			set
			{
				if (!(_QuickExperimentName == value))
				{
					_QuickExperimentName = value;
					OnPropertyChanged("QuickExperimentName");
				}
			}
		}

		public string QuickDefaultPath
		{
			get
			{
				return _QuickDefaultPath;
			}
			set
			{
				if (!(_QuickDefaultPath == value))
				{
					_QuickDefaultPath = value;
					OnPropertyChanged("QuickDefaultPath");
				}
			}
		}

		public object Experiment { get; set; }

		public ImageSource ImageSource
		{
			get
			{
				return _ImageSource;
			}
			set
			{
				if (_ImageSource != value)
				{
					_ImageSource = value;
					OnPropertyChanged("ImageSource");
				}
			}
		}

		public void SaveToStream(StreamEx stream)
		{
			stream.Write(PropertyKey.Key_QuickExperimentData);
			List<PropertyKey> list = new List<PropertyKey>();
			List<byte[]> list2 = new List<byte[]>();
			list.Add(PropertyKey.Key_ColorSettings);
			list2.Add(BytesConverter.GetBytes(Left));
			list.Add(PropertyKey.Key_QuickExperimentTop);
			list2.Add(BytesConverter.GetBytes(Top));
			list.Add(PropertyKey.Key_QuickExperimentName);
			list2.Add(BytesConverter.GetBytes(QuickExperimentName));
			list.Add(PropertyKey.Key_IsShowInCanvas);
			list2.Add(BytesConverter.GetBytes(IsShowInCanvas));
			list.Add(PropertyKey.Key_CanvasWidth);
			list2.Add(BytesConverter.GetBytes(CanvasWidth));
			list.Add(PropertyKey.Key_QuickExperimentIndex);
			list2.Add(BytesConverter.GetBytes(Index));
			list.Add(PropertyKey.Key_QuickExperimentDefaultPath);
			list2.Add(BytesConverter.GetBytes(QuickDefaultPath));
			stream.Write(PropertyKey.Key_Index);
			stream.WriteIndex(list, list2);
			stream.Flush();
		}

		public bool ReadFromStream(StreamEx stream)
		{
			PropertyKey propertyKey = stream.ReadKey();
			if (propertyKey == PropertyKey.Key_QuickExperimentData)
			{
				propertyKey = stream.ReadKey();
				if (propertyKey == PropertyKey.Key_Index)
				{
					List<PropertyKey> keys;
					List<byte[]> dates;
					stream.ReadIndex(out keys, out dates);
					for (int i = 0; i < keys.Count; i++)
					{
						switch (keys[i])
						{
						case PropertyKey.Key_ColorSettings:
							Left = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_QuickExperimentTop:
							Top = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_QuickExperimentName:
							QuickExperimentName = BytesConverter.BytesToString(dates[i]);
							break;
						case PropertyKey.Key_IsShowInCanvas:
							IsShowInCanvas = BytesConverter.BytesToBool(dates[i]);
							break;
						case PropertyKey.Key_CanvasWidth:
							CanvasWidth = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_QuickExperimentIndex:
							Index = BytesConverter.BytesToInt(dates[i]);
							break;
						case PropertyKey.Key_QuickExperimentDefaultPath:
							QuickDefaultPath = BytesConverter.BytesToString(dates[i]);
							break;
						}
					}
					return true;
				}
				stream.Seek(-4L, SeekOrigin.Current);
				return false;
			}
			stream.Seek(-4L, SeekOrigin.Current);
			return false;
		}
	}
}
